/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.data;

import java.sql.*;
import java.util.*;

/**
 *
 * @author Guesmi
 */
public class Intervention extends ITable {

    private static final String Table = "INTERVENTION";

    private int INT_ID;
    private int REC_ID;
    private String ETAT;
    private String INT_DATE;

    public String getETAT() {
        return ETAT;
    }

    public void setETAT(String ETAT) {
        this.ETAT = ETAT;
    }

    public String getINT_COMMENT() {
        return INT_COMMENT;
    }

    public void setINT_COMMENT(String INT_COMMENT) {
        this.INT_COMMENT = INT_COMMENT;
    }

    public String getINT_DATE() {
        return INT_DATE;
    }

    public void setINT_DATE(String INT_DATE) {
        this.INT_DATE = INT_DATE;
    }

    public int getINT_ID() {
        return INT_ID;
    }

    public void setINT_ID(int INT_ID) {
        this.INT_ID = INT_ID;
    }

    public int getREC_ID() {
        return REC_ID;
    }

    public void setREC_ID(int REC_ID) {
        this.REC_ID = REC_ID;
    }
    private String INT_COMMENT;

    public void Intervention(){}

    public int GetIDIntervention(){return this.INT_ID;}
    
    public int GetIDReclamation(){
        return (this.REC_ID);
    }

    public String GetEtatReclamation(){return this.ETAT;}
    public String GetDateInetrvention(){return this.INT_DATE;}
    public String GetMsgIntervention(){return this.INT_COMMENT;}

    public void SetIDIntervention(int id){this.INT_ID = id;}
    public void SetIDReclamation(int id){this.REC_ID = id;}
    public void SetEtatReclamation(String etat){this.ETAT = etat;}
    public void SetDateInetrvention(String date){this.INT_DATE = date;}
    public void SetMsgIntervention(String msg){this.INT_COMMENT = msg;}

    public void LoadFromDB(String MAT){
    //ConnexionBD db = new ConnexionBD();
    try{
        ResultSet res = db.executerSelect(" Select * from "+ Intervention.Table +" where INT_ID ='" + MAT + "'");
        if(res.next())
        {
            this.INT_ID = res.getInt("INT_ID");
            this.REC_ID = res.getInt("REC_ID");
            this.ETAT = res.getString("ETAT");
            this.INT_DATE = res.getString("INT_DATE");
            this.INT_COMMENT = res.getString("INT_COMMENT");
        }
        
    }catch(Exception sqle){}
    }


    public void SaveToDB() throws Exception{
            db.InsertNewLine(Intervention.Table ,
                    "INT_ID",Integer.toString(this.INT_ID),
                    "REC_ID",Integer.toString(this.REC_ID),
                    "ETAT","'"+this.ETAT+"'",
                    "INT_DATE","'"+this.INT_DATE+"'",
                    "INT_COMMENT","'"+this.INT_COMMENT+"'");
    }



    public static Intervention SearchByID(int ID)
    {
        Intervention inter = new Intervention();
        try{
            ResultSet res = db.executerSelect("select * from "+ Intervention.Table +" where INT_ID ='"+ ID +"'");
            while (res.next())
            {
                inter.INT_ID = res.getInt("INT_ID");
                inter.REC_ID = res.getInt("REC_ID");
                inter.ETAT = res.getString("ETAT");
                inter.INT_DATE = res.getString("INT_DATE");
                inter.INT_COMMENT = res.getString("INT_COMMENT");

            }
        }catch(Exception sqle){}
        
        return inter ;
    }

    public static ArrayList<Intervention> SearchByRecID(int ID)
    {
        ArrayList<Intervention> list = new ArrayList<Intervention>();
        
        try{
            ResultSet res = db.executerSelect("select * from "+ Intervention.Table +" where REC_ID ='"+ ID +"'");
            while (res.next())
            {
                Intervention inter = new Intervention();
                inter.INT_ID = res.getInt("INT_ID");
                inter.REC_ID = res.getInt("REC_ID");
                inter.ETAT = res.getString("ETAT");
                inter.INT_DATE = res.getString("INT_DATE");
                inter.INT_COMMENT = res.getString("INT_COMMENT");
                list.add(inter);
            }
        }catch(Exception sqle){}

        return list ;
    }

    public static ArrayList<Intervention> getAll()
    {
        ArrayList<Intervention> list = new ArrayList<Intervention>();
        try{
            ResultSet res = db.executerSelect("select * from "+ Intervention.Table);
            if(res.next())
            {
                Intervention inter = new Intervention();
                inter.INT_ID = res.getInt("INT_ID");
                inter.REC_ID = res.getInt("REC_ID");
                inter.ETAT = res.getString("ETAT");
                inter.INT_DATE = res.getString("INT_DATE");
                inter.INT_COMMENT = res.getString("INT_COMMENT");
                list.add(inter);
            }
            System.out.println("La liste contient :"+ list.size() +" Interventions .");
        }catch(Exception sqle){}
        return list ;
    }

    public static ArrayList<Intervention> SearchByEtat(String etat){
        ArrayList<Intervention> list = new ArrayList<Intervention>();
        try{
            ResultSet res = db.executerSelect("select * from "+ Intervention.Table +" where ETAT ='"+ etat +"'");
            if(res.next())
            {
                Intervention inter = new Intervention();
                inter.INT_ID = res.getInt("INT_ID");
                inter.REC_ID = res.getInt("REC_ID");
                inter.ETAT = res.getString("ETAT");
                inter.INT_DATE = res.getString("INT_DATE");
                inter.INT_COMMENT = res.getString("INT_COMMENT");
                list.add(inter);
            }
            System.out.println("La liste contient :"+ list.size() +" Interventions .");
        }catch(Exception sqle){}
        return list ;
    }




}
